page.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use client";
  2. import { GameListRep, getFreeGamesApi, SearchProps } from "@/api/home";
  3. import Box from "@/components/Box";
  4. import GroupCard from "@/components/Card/GroupCard";
  5. import HeaderBack from "@/components/HeaderBack";
  6. import {
  7. BalanceContent,
  8. BonusContent,
  9. FreeContent,
  10. ReplayContent,
  11. } from "@/components/ModalPopup/WalletDescribeModal";
  12. import TipsModal, { ModalProps } from "@/components/TipsModal";
  13. import { useWalletStore } from "@/stores/useWalletStore";
  14. import { Pagination, WalletEnum } from "@/types";
  15. import { useSetState } from "ahooks";
  16. import { InfiniteScroll } from "antd-mobile";
  17. import { useTranslations } from "next-intl";
  18. import { FC, useRef, useState } from "react";
  19. const Header = () => {
  20. const { wallet } = useWalletStore((state) => ({
  21. wallet: state.wallet,
  22. }));
  23. const t = useTranslations("ProfilePage");
  24. const tipsRef = useRef<ModalProps>(null);
  25. const [tipsStatus, setTipsStatus] = useState<keyof typeof WalletEnum>("Bonus");
  26. const modalHandler = (key: keyof typeof WalletEnum) => {
  27. setTipsStatus(key);
  28. tipsRef.current?.onOpen();
  29. };
  30. return (
  31. <>
  32. <HeaderBack showBack={true} title={"Free Games"}>
  33. <div
  34. className={"mr-[0.2083rem] flex items-center justify-end"}
  35. onClick={() => modalHandler("Free")}
  36. >
  37. <i className={"iconfont icon-qianbao3 text-[28px]"}></i>
  38. <span className={"ml-[10px] text-[22px]"}>{wallet.free_score}</span>
  39. </div>
  40. </HeaderBack>
  41. <TipsModal
  42. ref={tipsRef}
  43. title={
  44. <div className={"flex items-center"}>
  45. <i
  46. className={"iconfont icon-liwuhuodong mr-[0.0694rem] text-[0.2778rem]"}
  47. ></i>
  48. {t("modalTitle")}
  49. </div>
  50. }
  51. >
  52. {/*现金*/}
  53. {tipsStatus === WalletEnum.Balance ? <BalanceContent wallet={wallet} /> : null}
  54. {/* 彩金*/}
  55. {tipsStatus === WalletEnum.Bonus ? <BonusContent wallet={wallet} /> : null}
  56. {/* 免费币 */}
  57. {tipsStatus === WalletEnum.Free ? <FreeContent wallet={wallet} /> : null}
  58. {/* 重玩币 */}
  59. {tipsStatus === WalletEnum.Replay ? <ReplayContent wallet={wallet} /> : null}
  60. </TipsModal>
  61. </>
  62. );
  63. };
  64. const GameListFlag: FC = () => {
  65. const [target, setTarget] = useSetState<{ games: GameListRep[]; page: Partial<Pagination> }>({
  66. games: [],
  67. page: { is_end: false },
  68. });
  69. const params = useRef<SearchProps>({
  70. current_page: 0,
  71. page_size: 15,
  72. use_page: true,
  73. });
  74. const getGames = async (): Promise<GameListRep[] | undefined> => {
  75. return getFreeGamesApi(params.current).then((res) => {
  76. if (res.code === 200) {
  77. setTarget((value) => ({ page: res.page, games: [...value.games, ...res.data] }));
  78. return res.data;
  79. }
  80. });
  81. };
  82. const loadMore = async () => {
  83. params.current.current_page += 1;
  84. await getGames();
  85. };
  86. return (
  87. <>
  88. <Header />
  89. <main className={"main-header bg-[#1f1f1f]"}>
  90. <Box>
  91. <GroupCard data={target.games} row={1} groupType={2} />
  92. <InfiniteScroll loadMore={loadMore} hasMore={!target.page.is_end!} />
  93. </Box>
  94. </main>
  95. </>
  96. );
  97. };
  98. export default GameListFlag;